
package com.epam.android.training.level1.util;

import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;
import android.util.Log;

import java.io.Closeable;
import java.io.IOException;

/**
 * @author Anton Novikov
 */
public final class IOUtils {
  private static final String TAG = IOUtils.class.getSimpleName();

  /**
   * Creates an instance of IOUtils.
   */
  private IOUtils() {}

  public static void close(Closeable resource) {
    if (resource != null) {
      try {
        resource.close();
      } catch (IOException e) {
        Log.e(TAG, "Unable to close resource.", e);
      }
    }
  }

  public static void closeCursor(Cursor cursor) {
    if (cursor != null) {
      cursor.close();
    }
  }

  public static void closeStmt(SQLiteStatement stmt) {
    if (stmt != null) {
      stmt.close();
    }
  }
}
